package com.itheima.service.impl;

import com.itheima.annotation.MyAnno;
import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service   //  控制反转,spring扫描到该注解会自动创建其对象放入IOC容器
public class DeptServiceImpl implements DeptService {
        //    创建共用实现类
    @Autowired  // 依赖注入,引入dao类, 让spring帮我们注入,数据由IOC容器提供
    private DeptMapper deptMapper ;

    @Override
    public List<Dept> list(){
        List<Dept> deptList = deptMapper.list();
        return deptList;
    }

    @MyAnno
    @Override
    public void delete(Integer id) {
        deptMapper.delete(id);
    }

    @MyAnno
    @Override
    public void add(Dept dept) {
//        给dept对象设置创建时间和修改时间
        dept.setUpdateTime(LocalDateTime.now());
        dept.setCreateTime(LocalDateTime.now());

//        参数传给Mapper层
        deptMapper.insert(dept);
    }

    @Override
    public Dept getInfo(Integer id) {
        Dept dept = deptMapper.getById(id);
        return dept;
    }

    @MyAnno
    @Override
    public void update(Dept dept) {
        dept.setUpdateTime(LocalDateTime.now());
        deptMapper.update(dept);
    }


}
